﻿@model CategoryUpdateViewModel

@{
    ViewBag.Title = "文章类别";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Update</title>
</head>
<body>

    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-headline">
                <div class="panel-heading">
                    <h2 class="panel-title">编辑文章类别信息</h2>
                </div>

                <div class="panel-body">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-8">
                                <form method="post">
                                    <div class="form-group">
                                        <label for="Title">类别名称:</label>
                                            <input asp-for="Title" class="form-control" />
                                        <span asp-validation-for="Title"></span>
                                    </div>

                                    <div class="form-group">
                                        <label for="ParentList">菜单等级:</label>
                                        <select id="FirstMenu" name="ParentList" class="form-control">
                                            @if (Model.ParentList[0] == 1)
                                            {
                                                <option value="1" selected>一级菜单</option>
                                                <option value="2">二级菜单</option>
                                            }
                                            else if (Model.ParentList[0] == 2)
                                            {
                                                <option value="1">一级菜单</option>
                                                <option value="2" selected>二级菜单</option>
                                            }

                                        </select>
                                        <br/>
                                        <select id="secondMenu" class="form-control" name="ParentList" style="display:none;"></select>
                                    </div>

                                    <div class="form-group">
                                        <button class="btn btn-primary">提交</button>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

    @section Scripts
    {
        
        <script>
            
        $(function()
        {
            var FirstMenu = $("#FirstMenu").val();
            console.log(FirstMenu);
            if(FirstMenu == 2)
            {
                $("#secondMenu").show();
                $("#thirdMenu").hide();

                $.get("../../../ForumManage/Category/GetSysMenuList",function(data)
                {
                    
                    var str = "";
                    for(let i = 0; i < data.length; i++)
                    {
                        if(data[i].id == @Model.ParentList[1])
                        {
                            str += "<option value='"+data[i].id+"' selected>"+data[i].title+"</option>";
                        }
                        else
                        {
                            str += "<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                        }
                    }
                    $("#secondMenu").html(str);
                },"json");
            }
            if(FirstMenu == 3)
            {
                $("#secondMenu").show();
                $("#thirdMenu").show();

                $.get("../../../ForumManage/Category/GetSysMenuList",function(data)
                {
                    var str = "";
                    for(let i = 0; i < data.length; i++)
                    {
                        if(data[i].id == @Model.ParentList[1])
                        {
                            str += "<option value='"+data[i].id+"' selected>"+data[i].title+"</option>";
                        }
                        else
                        {
                            str += "<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                        }
                    }
                    $("#secondMenu").html(str);
                },"json");
            }
            else
            {
                $("#secondMenu").hide();
            }
        });

        $("#FirstMenu").change(function(){
          let msg =  $(this).val();
          console.log(msg);
          if(msg == 2)
          {
            $("#secondMenu").show();
                $.get("../../ForumManage/Category/GetSysMenuList",function(data){
                 //用户得到所有的一级菜单值,并且把这个值存放到secondMenu下拉列表当中
                   // console.log(data);
                 //我们需要把data当中的内容绑定到对应的下拉列表当中
                 var str ="";
                 for(let i = 0 ; i < data.length;i++)
                 {
                    str +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                 }

                 $("#secondMenu").html(str);

                },"json");
          }
          else
          {
            $("#secondMenu").hide();
          }
    });

        </script>

    }


</body>
</html>
